package com.zygh.policeasset.component;

import com.zygh.policeasset.mapper.AssetsMapper;
import com.zygh.policeasset.mapper.BasicsMapper;
import com.zygh.policeasset.mapper.ExcelMapper;
import com.zygh.policeasset.mapper.HardwitMapper;
import com.zygh.policeasset.mapper.PurchaseMapper;
import com.zygh.policeasset.mapper.SoftwitMapper;
import com.zygh.policeasset.pojo.Assets;
import com.zygh.policeasset.pojo.Basics;
import com.zygh.policeasset.pojo.DailyAsset;
import com.zygh.policeasset.pojo.DailyProject;
import com.zygh.policeasset.pojo.Hardwit;
import com.zygh.policeasset.pojo.Purchase;
import com.zygh.policeasset.pojo.Report;
import com.zygh.policeasset.pojo.Softwit;
import com.zygh.policeasset.service.DailyAssetsService;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

@Component
/* loaded from: police-asset-2.0-0.0.1-SNAPSHOT.jar:BOOT-INF/classes/com/zygh/policeasset/component/ReportComponent.class */
public class ReportComponent {
    @Autowired
    HardwitMapper hardwitMapper;
    @Autowired
    SoftwitMapper softwitMapper;
    @Autowired
    BasicsMapper basicsMapper;
    @Autowired
    PurchaseMapper purchaseMapper;
    @Autowired
    ExcelMapper excelMapper;
    @Autowired
    DailyAssetsService dailyAssetsService;
    @Autowired
    AssetsMapper assetsMapper;

    @Async("asyncTaskExecutor")
    public CompletableFuture<List<Report>> getcg(List<Report> list) throws ParseException {
        List<Report> reportList = new ArrayList<>();
        for (Report basics : list) {
            List<Purchase> purchaseList = this.purchaseMapper.findByProjectNo(basics.getProjectNo());
            Double sum = Double.valueOf(0.0D);
            Double zje = Double.valueOf(0.0D);
            for (Purchase purchase : purchaseList) {
                Double a = Double.valueOf(Double.parseDouble(purchase.getMoney()));
                sum = Double.valueOf(sum.doubleValue() + a.doubleValue());
                zje = Double.valueOf(zje.doubleValue() + ((a.doubleValue() / ((double) (Integer.parseInt(purchase.getDepreciationYear()) * 12))) * ((double) getCountMonth(purchase.getGetDatetime()))));
            }
            BigDecimal sum1 = new BigDecimal(sum.doubleValue()).setScale(2, RoundingMode.UP);
            BigDecimal zje1 = new BigDecimal(zje.doubleValue()).setScale(2, RoundingMode.UP);
            Report report = new Report();
            report.setName(basics.getName());
            report.setType("采购");
            report.setProjectNo(basics.getProjectNo());
            report.setSum(String.valueOf(sum1));
            if (zje.doubleValue() > sum.doubleValue()) {
                report.setNumber1(String.valueOf(sum1));
                report.setNumber2("0");
            } else {
                report.setNumber1(String.valueOf(zje1));
                report.setNumber2(String.valueOf(sum1.subtract(zje1).doubleValue()));
            }
            reportList.add(report);
            System.out.println(report);
        }
        return CompletableFuture.completedFuture(reportList);
    }

    @Async("asyncTaskExecutor")
    public CompletableFuture<List<Report>> getjc(List<Report> list) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        List<Report> reportList = new ArrayList<>();
        for (Report basics : list) {
            List<Basics> basicsList = this.basicsMapper.findBySectionId(basics.getSectionId());
            Double sum = Double.valueOf(0.0D);
            Double zje = Double.valueOf(0.0D);
            for (Basics basics1 : basicsList) {
                Double a = Double.valueOf(((double) basics1.getNumber().intValue()) * Double.parseDouble(basics1.getStartMoney()));
                sum = Double.valueOf(sum.doubleValue() + a.doubleValue());
                if (sdf.parse("2020-01-01").before(sdf.parse(basics1.getStopTime()))) {
                    zje = Double.valueOf(zje.doubleValue() + ((a.doubleValue() / ((double) (basics1.getDepreciationPeriod().intValue() * 12))) * ((double) getCountMonth(basics1.getAudit_time()))));
                } else {
                    zje = Double.valueOf(zje.doubleValue() + ((a.doubleValue() / ((double) (basics1.getDepreciationPeriod().intValue() * 12))) * ((double) getCountMonth(basics1.getStopTime()))));
                }
            }
            BigDecimal sum1 = new BigDecimal(sum.doubleValue()).setScale(2, RoundingMode.UP);
            BigDecimal zje1 = new BigDecimal(zje.doubleValue()).setScale(2, RoundingMode.UP);
            Report report = new Report();
            report.setName(basics.getName());
            report.setType("基础");
            report.setProjectNo(basics.getProjectNo());
            report.setSectionName(basics.getSectionName());
            report.setSectionId(basics.getSectionId());
            report.setSum(String.valueOf(sum1));
            if (zje.doubleValue() > sum.doubleValue()) {
                report.setNumber1(String.valueOf(sum1));
                report.setNumber2("0");
            } else {
                report.setNumber1(String.valueOf(zje1));
                report.setNumber2(String.valueOf(sum1.subtract(zje1).doubleValue()));
            }
            reportList.add(report);
        }
        return CompletableFuture.completedFuture(reportList);
    }

    @Async("asyncTaskExecutor")
    public CompletableFuture<List<Report>> getda(List<DailyProject> list) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        List<Report> reportList = new ArrayList<>();
        for (DailyProject basics : list) {
            List<DailyAsset> basicsList = this.dailyAssetsService.findAllBybuildNum(String.valueOf(basics.getId()));
            Double sum = Double.valueOf(0.0D);
            Double zje = Double.valueOf(0.0D);
            for (DailyAsset basics1 : basicsList) {
                Double a = Double.valueOf(((double) basics1.getNumber().intValue()) * Double.parseDouble(basics1.getStartMoney()));
                sum = Double.valueOf(sum.doubleValue() + a.doubleValue());
                if (sdf.parse("2020-01-01").before(sdf.parse(basics1.getStopTime()))) {
                    zje = Double.valueOf(zje.doubleValue() + ((a.doubleValue() / ((double) (basics1.getPlanYear().intValue() * 12))) * ((double) getCountMonth(basics1.getStopTime()))));
                } else {
                    zje = Double.valueOf(zje.doubleValue() + ((a.doubleValue() / ((double) (basics1.getPlanYear().intValue() * 12))) * ((double) getCountMonth(basics1.getStopTime()))));
                }
            }
            BigDecimal sum1 = new BigDecimal(sum.doubleValue()).setScale(2, RoundingMode.UP);
            BigDecimal zje1 = new BigDecimal(zje.doubleValue()).setScale(2, RoundingMode.UP);
            Report report = new Report();
            report.setName(basics.getProjectName());
            report.setType("日常资产");
            report.setSum(String.valueOf(sum1));
            if (zje.doubleValue() > sum.doubleValue()) {
                report.setNumber1(String.valueOf(sum1));
                report.setNumber2("0");
            } else {
                report.setNumber1(String.valueOf(zje1));
                report.setNumber2(String.valueOf(sum1.subtract(zje1).doubleValue()));
            }
            reportList.add(report);
        }
        return CompletableFuture.completedFuture(reportList);
    }

    @Async("asyncTaskExecutor")
    public CompletableFuture<List<Report>> getznhw(List<Report> list) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        List<Report> reportList = new ArrayList<>();
        for (Report report1 : list) {
            List<Hardwit> hardwitList = this.hardwitMapper.findBySectionId(report1.getSectionId());
            Double sum = Double.valueOf(0.0D);
            Double zje = Double.valueOf(0.0D);
            for (Hardwit hardwit : hardwitList) {
                Double a = Double.valueOf(Double.parseDouble(hardwit.getStartMoney()));
                sum = Double.valueOf(sum.doubleValue() + a.doubleValue());
                if (sdf.parse("2020-01-01").before(sdf.parse(hardwit.getStopTime()))) {
                    zje = Double.valueOf(zje.doubleValue() + ((a.doubleValue() / ((double) (hardwit.getDepreciationPeriod().intValue() * 12))) * ((double) getCountMonth(hardwit.getAudit_time()))));
                } else {
                    zje = Double.valueOf(zje.doubleValue() + ((a.doubleValue() / ((double) (hardwit.getDepreciationPeriod().intValue() * 12))) * ((double) getCountMonth(hardwit.getStopTime()))));
                }
            }
            List<Softwit> softwitList = this.softwitMapper.findBySectionId(report1.getSectionId());
            if (softwitList.size() > 0) {
                for (Softwit softwit : softwitList) {
                    Double a2 = Double.valueOf(Double.parseDouble(softwit.getStartMoney()));
                    sum = Double.valueOf(sum.doubleValue() + a2.doubleValue());
                    if (sdf.parse("2020-01-01").before(sdf.parse(softwit.getStopTime()))) {
                        System.out.println("按照内审时间折旧");
                        zje = Double.valueOf(zje.doubleValue() + ((a2.doubleValue() / ((double) (softwit.getDepreciationPeriod().intValue() * 12))) * ((double) getCountMonth(softwit.getAudit_time()))));
                    } else {
                        System.out.println("按照竣工验收时间折旧");
                        zje = Double.valueOf(zje.doubleValue() + ((a2.doubleValue() / ((double) (softwit.getDepreciationPeriod().intValue() * 12))) * ((double) getCountMonth(softwit.getStopTime()))));
                    }
                }
            }
            BigDecimal sum1 = new BigDecimal(sum.doubleValue()).setScale(2, RoundingMode.UP);
            BigDecimal zje1 = new BigDecimal(zje.doubleValue()).setScale(2, RoundingMode.UP);
            Report report = new Report();
            report.setName(report1.getName());
            report.setType("智能");
            report.setProjectNo(report1.getProjectNo());
            report.setSectionName(report1.getSectionName());
            report.setSectionId(report1.getSectionId());
            report.setSum(String.valueOf(sum1));
            if (zje.doubleValue() > sum.doubleValue()) {
                report.setNumber1(String.valueOf(sum1));
                report.setNumber2("0");
            } else {
                report.setNumber1(String.valueOf(zje1));
                report.setNumber2(String.valueOf(sum1.subtract(zje1).doubleValue()));
            }
            reportList.add(report);
        }
        return CompletableFuture.completedFuture(reportList);
    }

    @Async("asyncTaskExecutor")
    public CompletableFuture<List<Report>> get(List<Report> list, String type) throws ParseException {
        new SimpleDateFormat("yyyy-MM-dd");
        List<Report> reportList = new ArrayList<>();
        for (Report report1 : list) {
            Assets assets = new Assets();
            assets.setBuildNum(report1.getProjectNo());
            assets.setSectionId(report1.getSectionId());
            List<Assets> assetsList = this.assetsMapper.findAll(assets);
            Double sum = Double.valueOf(0.0D);
            Double zje = Double.valueOf(0.0D);
            for (Assets assets1 : assetsList) {
                Double a = Double.valueOf(assets1.getCombined());
                sum = Double.valueOf(sum.doubleValue() + a.doubleValue());
                if (StringUtils.isEmpty(assets1.getStartProvisionDate())) {
                    zje = Double.valueOf(zje.doubleValue() + 0.0D);
                } else {
                    zje = Double.valueOf(zje.doubleValue() + ((a.doubleValue() / ((double) (assets1.getDepreciationYear().intValue() * 12))) * ((double) getCountMonth(assets1.getStartProvisionDate()))));
                }
            }
            BigDecimal sum1 = new BigDecimal(sum.doubleValue()).setScale(2, RoundingMode.UP);
            BigDecimal zje1 = new BigDecimal(zje.doubleValue()).setScale(2, RoundingMode.UP);
            Report report = new Report();
            report.setName(report1.getName());
            report.setType(type);
            report.setProjectNo(report1.getProjectNo());
            report.setSectionName(report1.getSectionName());
            report.setSectionId(report1.getSectionId());
            report.setSum(String.valueOf(sum1));
            if (zje.doubleValue() > sum.doubleValue()) {
                report.setNumber1(String.valueOf(sum1));
                report.setNumber2("0");
            } else {
                report.setNumber1(String.valueOf(zje1));
                report.setNumber2(String.valueOf(sum1.subtract(zje1).doubleValue()));
            }
            reportList.add(report);
        }
        return CompletableFuture.completedFuture(reportList);
    }

    @Async("asyncTaskExecutor")
    public CompletableFuture<List<Report>> getznsw(List<Report> list) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        List<Report> reportList = new ArrayList<>();
        for (Report report1 : list) {
            List<Softwit> softwitList = this.softwitMapper.findBySectionId(report1.getSectionId());
            List<Hardwit> hardwitList = this.hardwitMapper.findBySectionId(report1.getSectionId());
            if (softwitList.size() > 0 && hardwitList.size() == 0) {
                Double sum = Double.valueOf(0.0D);
                Double zje = Double.valueOf(0.0D);
                for (Softwit softwit : softwitList) {
                    Double a = Double.valueOf(Double.parseDouble(softwit.getStartMoney()));
                    sum = Double.valueOf(sum.doubleValue() + a.doubleValue());
                    if (sdf.parse("2020-01-01").before(sdf.parse(softwit.getStopTime()))) {
                        zje = Double.valueOf(zje.doubleValue() + ((a.doubleValue() / ((double) (Integer.parseInt(softwit.getPlanYear()) * 12))) * ((double) getCountMonth(softwit.getAudit_time()))));
                    } else {
                        zje = Double.valueOf(zje.doubleValue() + ((a.doubleValue() / ((double) (Integer.parseInt(softwit.getPlanYear()) * 12))) * ((double) getCountMonth(softwit.getStopTime()))));
                    }
                }
                BigDecimal sum1 = new BigDecimal(sum.doubleValue()).setScale(2, RoundingMode.UP);
                BigDecimal zje1 = new BigDecimal(zje.doubleValue()).setScale(2, RoundingMode.UP);
                Report report = new Report();
                report.setName(report1.getName());
                report.setType("智能");
                report.setProjectNo(report1.getProjectNo());
                report.setSectionName(report1.getSectionName());
                report.setSectionId(report1.getSectionId());
                report.setSum(String.valueOf(sum1));
                if (zje.doubleValue() > sum.doubleValue()) {
                    report.setNumber1(String.valueOf(sum1));
                    report.setNumber2("0");
                } else {
                    report.setNumber1(String.valueOf(zje1));
                    report.setNumber2(String.valueOf(sum1.subtract(zje1).doubleValue()));
                }
                reportList.add(report);
            }
        }
        return CompletableFuture.completedFuture(reportList);
    }

    public int getCountMonth(String time1) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        String nowTime = sdf.format(new Date());
        Calendar bef = Calendar.getInstance();
        Calendar aft = Calendar.getInstance();
        bef.setTime(sdf.parse(time1));
        aft.setTime(sdf.parse(nowTime));
        return Math.abs(((aft.get(1) - bef.get(1)) * 12) + (aft.get(2) - bef.get(2)));
    }
}


